/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * com_distri_compras.java
 *
 * Created on 25/08/2011, 11:53:43 AM
 */

package sie_invdis;



import java.sql.*;
import javax.swing.*;

import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTable.*;
import java.awt.*;
import java.util.Date;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.text.*;
import javax.swing.table.DefaultTableCellRenderer;
/**
 *
 * @author Michelle
 */
public class com_distri_compras extends javax.swing.JFrame {


     private javax.swing.table.DefaultTableModel jtable_modelo;
     private javax.swing.table.DefaultTableModel jtable_modelofle;
     private javax.swing.table.DefaultTableModel jtable_modeloventas;

     private int buscamp=1;


    private int control_enter=0,controlcombo=0,contagarbaje=0;
    private SimpleDateFormat formateador = new SimpleDateFormat("dd-MM-yyyy");
    private SimpleDateFormat formateadoresta = new SimpleDateFormat("yyyy-MM-dd");

    DefaultTableCellRenderer alinearCentro, alinearderecha, alinearIzquierda;
    //se crea intancia de la clase conexion
       bd_conexion x = new bd_conexion() ;
       //se creaa la variable resultset
       ResultSet rs = null;
    /** Creates new form com_distri_compras */
public com_distri_compras() {
        this.iniciar_modelo_de_tabla();
        this.iniciar_modelo_flete();
        this.iniciar_modelo_ventas();
        initComponents();
        this.carga_datos(0,"");
        this.carga_datos_fletes(0,"");
        this.jtf_busqueda.requestFocus();
        jtb_comprascatalogo.getColumnModel().getColumn(0).setPreferredWidth(60);//Status
        jtb_comprascatalogo.getColumnModel().getColumn(1).setPreferredWidth(20);//Folio
        jtb_comprascatalogo.getColumnModel().getColumn(2).setPreferredWidth(35);//doc referencia
        jtb_comprascatalogo.getColumnModel().getColumn(3).setPreferredWidth(35);//fecha docto
        jtb_comprascatalogo.getColumnModel().getColumn(4).setPreferredWidth(35);//fecha llega almacen
        jtb_comprascatalogo.getColumnModel().getColumn(5).setPreferredWidth(35);//f.recepcion
        jtb_comprascatalogo.getColumnModel().getColumn(6).setPreferredWidth(35);//dias trans
        jtb_comprascatalogo.getColumnModel().getColumn(7).setPreferredWidth(60);//viaje
        jtb_comprascatalogo.getColumnModel().getColumn(8).setPreferredWidth(120);//proveedor
        jtb_comprascatalogo.getColumnModel().getColumn(9).setPreferredWidth(35);//piezas
        jtb_comprascatalogo.getColumnModel().getColumn(10).setPreferredWidth(35);//costo
        jtb_comprascatalogo.getColumnModel().getColumn(11).setPreferredWidth(35);//precio
        jtb_comprascatalogo.getColumnModel().getColumn(12).setPreferredWidth(120);//observaciones
        this.buttonGroup1.setSelected(jrbtn_folio.getModel(), true);
        this.loadcombo();

        Calendar fechaini = Calendar.getInstance(); // obtiene la fecha actual
        fechaini.add(Calendar.DATE, -1); // decrementa la fecha en 3 dias.
        this.jdc_fechainicial.setDate(fechaini.getTime());
        this.jdc_fechafinal.setDate(fechaini.getTime());

    }


private void iniciar_modelo_de_tabla()
    {
        jtable_modelo=new javax.swing.table.DefaultTableModel();//Creo el modelo
        jtable_modelo.addColumn("<html><b>Status</b></html>");
        jtable_modelo.addColumn("<html><b>Folio</b></html>");
        jtable_modelo.addColumn("<html><b>Doc. Ref.</b></html>");
        jtable_modelo.addColumn("<html><b>F.Alt. Sist</b></html>");
        jtable_modelo.addColumn("<html><b>F.doc prov.</b></html>");
        jtable_modelo.addColumn("<html><b>F.Recibi Merca.</b></html>");
        jtable_modelo.addColumn("<html><b>R.Blister</b></html>");
        jtable_modelo.addColumn("<html><b>Viaje</b></html>");
        jtable_modelo.addColumn("<html><b>Proveedor</b></html>");
        jtable_modelo.addColumn("<html><b>Piezas</b></html>");
        jtable_modelo.addColumn("<html><b>Costo</b></html>");
        jtable_modelo.addColumn("<html><b>Precio Venta</b></html>");
        jtable_modelo.addColumn("<html><b>Observaciones</b></html>");
   }
private void iniciar_modelo_flete()
    {
        jtable_modelofle=new javax.swing.table.DefaultTableModel();//Creo el modelo
        jtable_modelofle.addColumn("<html><b>Folio</b></html>");
        jtable_modelofle.addColumn("<html><b>Guia</b></html>");
        jtable_modelofle.addColumn("<html><b>Fecha</b></html>");
        jtable_modelofle.addColumn("<html><b>caja</b></html>");
        jtable_modelofle.addColumn("<html><b>Remisiones</b></html>");
        jtable_modelofle.addColumn("<html><b>Flete</b></html>");
        jtable_modelofle.addColumn("<html><b>servicio</b></html>");
        jtable_modelofle.addColumn("<html><b>Hora</b></html>");
        jtable_modelofle.addColumn("<html><b>Cliente</b></html>");
   }
private void iniciar_modelo_ventas()
    {

        jtable_modeloventas=new javax.swing.table.DefaultTableModel();//Creo el modelo
        jtable_modeloventas.addColumn("<html><b>Viaje</b></html>");
        jtable_modeloventas.addColumn("<html><b>Cliente</b></html>");
        jtable_modeloventas.addColumn("<html><b>Folio</b></html>");
        jtable_modeloventas.addColumn("<html><b>Status</b></html>");
        jtable_modeloventas.addColumn("<html><b>Ref Proveedor</b></html>");
        jtable_modeloventas.addColumn("<html><b>Fecha</b></html>");
        jtable_modeloventas.addColumn("<html><b>F.Recepcion</b></html>");
        jtable_modeloventas.addColumn("<html><b>F.Doc.Prov</b></html>");
        jtable_modeloventas.addColumn("<html><b>Proveedor</b></html>");
        jtable_modeloventas.addColumn("<html><b>Piezas</b></html>");
        jtable_modeloventas.addColumn("<html><b>C.Compra</b></html>");
        jtable_modeloventas.addColumn("<html><b>C.Integrado</b></html>");
   }

public void centrar_datos()
    {
        alinearderecha = new DefaultTableCellRenderer();
        alinearderecha.setHorizontalAlignment(SwingConstants.RIGHT);

        jtb_comprascatalogo.getColumnModel().getColumn(9).setCellRenderer(alinearderecha);
        jtb_comprascatalogo.getColumnModel().getColumn(10).setCellRenderer(alinearderecha);
        jtb_comprascatalogo.getColumnModel().getColumn(11).setCellRenderer(alinearderecha);

    }
private void carga_datos(int opbus,String tbusca)
    {
        String fechacat = "",fechallegatienda="",fechaentrega="",abrehtml="",cierrahtml="";
        DecimalFormat miformat = new DecimalFormat("###,###,###,###.##");
        while(jtable_modelo.getRowCount()>0)jtable_modelo.removeRow(0);
        float tpz=0,tcd=0,tpp=0;
        Object[] fnewRow = new Object[13];

       //invoco al metodo que trae el recordset de datos

        try
         {
            rs = x.sieuno_executediversosv2("select * from x1distribucion_terminados_compras_catalogov3("+opbus+",'"+tbusca+"') as (idreg integer,iddocumento character varying(12),idstatus smallint,statusdescribe character varying(15),doctoanterior character varying(12),fechadocto date,fechadoctoenmes text,idproveedor character varying(12),describeproveedor character varying(60),observadocto character varying(80),usuario character varying(20),impuestoporcen numeric,descuentototal numeric,clasificacion smallint,describeclasificacion character varying(30),clasifechainicio date,clasifechafin date,clavepersonaldoc character varying(45),docsiguiente character varying(12),fechaentrega date,fechavenci date,impuestoporcen2 numeric,descuentofinan numeric,piezas numeric,totalimporte numeric,totalprecio numeric,idsubfam smallint,diasenalmacen integer,diasproveealmacen integer,rembli text,costobli numeric);",variables_global.getconexiongral());
            while (rs.next())
                {
                   if(rs.getInt("idstatus") > 3)
                        {
                            abrehtml="<html><b><font color=#CC0000>";
                            cierrahtml="<font></b></html>";
                        }
                   else
                        {
                            abrehtml="<html>";
                            cierrahtml="</html>";
                        }
                 fnewRow[0]=abrehtml+rs.getString ("idstatus")+":"+rs.getString ("statusdescribe")+cierrahtml;
                 fnewRow[1]=rs.getString ("iddocumento");
                 fnewRow[2]=abrehtml+rs.getString ("doctoanterior")+cierrahtml;
                 fnewRow[3]=abrehtml+this.fechaeuropea( rs.getString ("fechadocto"))+":<br>"+DiaSemana(this.fechaeuropea(rs.getString("fechadocto")))+cierrahtml;
                 if(rs.getString("fechaentrega") != null)
                        {
                           fechallegatienda=abrehtml+ this.fechaeuropea(rs.getString("fechaentrega"))+":<br>"+DiaSemana(this.fechaeuropea(rs.getString ("fechaentrega")))+cierrahtml;
                        }
                 fnewRow[4]=fechallegatienda;
                 if(rs.getString("fechavenci") != null )
                        {
                            fechaentrega=abrehtml+this.fechaeuropea(rs.getString ("fechavenci"))+":<br>"+this.DiaSemana(this.fechaeuropea(rs.getString("fechavenci")))+cierrahtml;
                        }
                 fnewRow[5]=fechaentrega;
                 fnewRow[6]=rs.getString("rembli");
                 fnewRow[7]=abrehtml+rs.getString ("clasificacion")+":"+rs.getString ("describeclasificacion")+cierrahtml;
                 fnewRow[8]=abrehtml+rs.getString ("idproveedor")+":"+rs.getString ("describeproveedor")+cierrahtml;
                 fnewRow[9]=abrehtml+miformat.format(rs.getFloat("piezas"))+cierrahtml;
                 fnewRow[10]=abrehtml+miformat.format(rs.getFloat("totalimporte"))+cierrahtml;
                 fnewRow[11]=abrehtml+miformat.format(rs.getFloat("totalprecio"))+cierrahtml;
                 fnewRow[12]=abrehtml+rs.getString ("observadocto")+cierrahtml;
                 jtable_modelo.addRow(fnewRow);
                 tpz+=rs.getFloat("piezas");
                 tcd+=rs.getFloat("totalimporte");
                 tpp+=rs.getFloat("totalprecio");

                }
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
  
                fnewRow[0]="";
                 fnewRow[1]="";
                 fnewRow[2]="";
                 fnewRow[3]="";
                 fnewRow[4]="";
                 fnewRow[5]="";
                 fnewRow[6]="";
                 fnewRow[7]="";
                 fnewRow[8]="<html><h3>Totales:</h3></html>";
                 fnewRow[9]="<html><h3>"+miformat.format(tpz)+"</h3></html>";
                 fnewRow[10]="<html><h3>"+miformat.format(tcd)+"</h3></html>";
                 fnewRow[11]="<html><h3>"+miformat.format(tpp)+"</h3></html>";
                 fnewRow[12]="";
                 jtable_modelo.addRow(fnewRow);

        this.centrar_datos();
      }
private void carga_datos_fletes(int opbus,String tbusca)
    {
        String fechacat = "",fechallegatienda="",fechaentrega="",abrehtml="",cierrahtml="";
        DecimalFormat miformat = new DecimalFormat("###,###,###,###.##");
        while(jtable_modelofle.getRowCount()>0)jtable_modelofle.removeRow(0);
        float tpz=0,tcd=0,tpp=0;
        Object[] fnewRow = new Object[13];

       //invoco al metodo que trae el recordset de datos

        try
         {
            rs = x.sieuno_executediversosv2("select * from x1distribucion_terminados_compras_fletescatalogo("+opbus+",'"+tbusca+"','','') as (idfle integer,fecha date,fechae date,fechav date,guia text,cajas numeric,remi numeric,flete numeric, servicio text,usuario text,monto numeric,hora time,idcliente character varying(12));",variables_global.getconexiongral());
            while (rs.next())
                {

                 fnewRow[0]=rs.getString ("idfle");
                 fnewRow[1]=this.fechaeuropea(rs.getString("fecha"));
                 fnewRow[2]=rs.getString("hora").substring(0, 5);
                 fnewRow[3]=rs.getString("guia");
                 fnewRow[4]=rs.getString("cajas");
                 fnewRow[5]=rs.getString("remi");
                 fnewRow[6]=miformat.format(rs.getFloat("flete"));
                 fnewRow[7]=rs.getString("servicio");
                 jtable_modelofle.addRow(fnewRow);
                }
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }

      }

private void carga_datos_ventasyprov(int opbus,String cliente,String busca,String busca2)
    {
       String fechacat = "",fechallegatienda="",fechaentrega="";
       DecimalFormat miformat = new DecimalFormat("############.##");
       String abrehtml="",cierrahtml="";
        float tpz=0,tcd=0,tpp=0;
        Object[] fnewRow = new Object[12];

        while(jtable_modeloventas.getRowCount()>0)jtable_modeloventas.removeRow(0);
       //invoco al metodo que trae el recordset de datos
       String texto="select * from x1distribucion_terminados_ventasycompra_catalogo(2,'"+cliente+"','"+busca+"','"+busca2+"','','','') as (idr integer,id character varying(12),idesta smallint,desta character varying(15), cveper character varying(45),dante character varying(12),docsig character varying(12), fedoc date,feent date,fechaven date,impues numeric,impues2 numeric,desctotal numeric,descfin numeric,idclie character varying(12),nomclie character varying(60),obserdoc character varying(80), usuario character varying(20),flete numeric,guia character varying(60),fechae date,total numeric, tpz numeric,distra integer,diastra2 integer,clasi smallint,totalcosto numeric,subtotal numeric,subimp numeric,subdesc numeric,totalpreciopub numeric,descriprov character varying(60),desclasif character varying(30),docto_refcompra character varying(20));";
      System.out.println(texto);
        try
         {
            rs = x.sieuno_executediversosv2(texto,variables_global.getconexiongral());
            while (rs.next())
                {
                    fnewRow[0]=rs.getString ("desclasif");
                    fnewRow[1]=rs.getString ("nomclie");
                    fnewRow[2]=rs.getString ("id");
                    fnewRow[3]=rs.getString ("desta");
                    fnewRow[4]=rs.getString ("docto_refcompra");
                    if(rs.getString("fedoc") != null)
                        {
                               fnewRow[5]=""+this.fechaeuropea(rs.getString("fedoc"));
                        }
                   else
                        {
                            fnewRow[5]="";
                        }
                  if(rs.getString("feent") != null)
                    {
                           fnewRow[6]=""+this.fechaeuropea(rs.getString("feent"));
                    }
                  else
                    {
                        fnewRow[6]="";
                    }
                if(rs.getString("fechae") != null)
                    {
                           fnewRow[7]=""+this.fechaeuropea(rs.getString("fechae"));
                    }
                  else
                    {
                        fnewRow[7]="";
                    }
                 fnewRow[8]=rs.getString ("descriprov");
                 fnewRow[9]=abrehtml+miformat.format(rs.getFloat("tpz"))+cierrahtml;
                 fnewRow[10]=abrehtml+miformat.format(rs.getFloat("totalcosto"))+cierrahtml;
                 fnewRow[11]=abrehtml+miformat.format(rs.getFloat("total"))+cierrahtml;
                 jtable_modeloventas.addRow(fnewRow);
                 tpz+=rs.getFloat("tpz");
                 tcd+=rs.getFloat("totalcosto");
                 tpp+=rs.getFloat("total");

                }

        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
            this.jlbl_cantidadregistros.setText(String.valueOf(this.jtable_modeloventas.getRowCount()));
            

      }


private String  fechaeuropea(String fecha) {

         //resibe cadena de fecha en formato americano yyyy-MM-dd
       java.util.Date fechaestaeuropa=null;
       SimpleDateFormat formateadorestaeuropa = new SimpleDateFormat("dd-MM-yyyy");
       String cadenafecha="";
        try
         {
          fechaestaeuropa = formateadoresta.parse(fecha);
         }
        catch (ParseException e)
          {
             //Error, la cadena de texto no se puede convertir en fecha.
          }
       cadenafecha= formateadorestaeuropa.format(fechaestaeuropa);
       return cadenafecha;

    }
private String DiaSemana(String fe) {
         String dia = "";
       java.util.Date fecha=null;
         try
            {
             fecha = formateador.parse(fe);

           }
        catch (ParseException e)
            {
            //Error, la cadena de texto no se puede convertir en fecha.
            }
        Calendar cal= Calendar.getInstance();
        cal.setTime(fecha);
        //ojo para establecer o recetear cada parte de la fecha por separado
        //cal.set(Calendar.YEAR, fecha.getYear());
        //cal.set(Calendar.MONTH, fecha.getMonth());
        //cal.set(Calendar.DAY_OF_MONTH, fecha.getDay());
        int diaInt = cal.get(Calendar.DAY_OF_WEEK);
        switch (diaInt) {
            case 1:
                dia = "Domingo";
                break;
            case 2:
                dia = "Lunes";
                break;
            case 3:
                dia = "Martes";
                break;
            case 4:
                dia = "Miercoles";
                break;
            case 5:
                dia = "Jueves";
                break;
            case 6:
                dia = "Viernes";
                break;
            case 7:
                dia = "Sabado";
                break;

        }
        return dia;
    }

private  void ayuda()
    {
                JOptionPane.showMessageDialog(null," 1.-Catalogo de Recepciones de Mercancia, cada una de las Opciones se autodescribe brevemente\n 2.- Cada Boton tiene Una letra Resaltada el cual indica su metodo abreviado, uselo si desea mayor rapides ( ejemplo Alt+a obtendra ayuda automaticamente)\n 3.- Para ver Detalle de un documento de Doble clik sobre el registro sombreado o use las teclas arriba o abajo luego precione enter y aparecera otra pantalla. \n ", "Sistema Integral(Detalle Recepcion) : Ayuda",1);
    }

 private void loadcombo()
    {
            this.jcbx_tiendas.addItem("0:General:0");
          try
            {
               rs = x.sieuno_executediversosv2("select * from x1distribucion_tiendas_activas(7,'','') as (tie_descri character varying(35),tie_id integer,tie_desesque character varying(25),idclie character varying(12));",variables_global.getconexiongral());
               while (rs.next())
                    {
                          this.jcbx_tiendas.addItem(rs.getString("tie_id")+":"+rs.getString("tie_descri")+":"+rs.getString("idclie"));
                    }
            }
            catch(Exception e)
            {
                System.out.println(e.getMessage());
            }
       
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel2 = new javax.swing.JPanel();
        jtf_busqueda = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jbtn_busqueda = new javax.swing.JButton();
        jrbtn_folio = new javax.swing.JRadioButton();
        jrbtn_doctoanterio = new javax.swing.JRadioButton();
        jrbtn_obserdocto = new javax.swing.JRadioButton();
        jrbtn_cliente = new javax.swing.JRadioButton();
        jcbx_filtrarpendientes = new javax.swing.JCheckBox();
        jrbtn_idviaje = new javax.swing.JRadioButton();
        jrbtn_pendienterecep = new javax.swing.JRadioButton();
        jPanel3 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jbtn_agregarcompra = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtb_comprascatalogo = new javax.swing.JTable(){
            public boolean isCellEditable(int rowIndex, int mColIndex) {
                return false;
            }
        };
        jPanel4 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jtb_comprascatalogo1 = new javax.swing.JTable(){
            public boolean isCellEditable(int rowIndex, int mColIndex) {
                return false;
            }
        };
        jPanel5 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable(){
            public boolean isCellEditable(int rowIndex, int mColIndex) {
                return false;
            }
        };
        jLabel3 = new javax.swing.JLabel();
        jdc_fechainicial = new com.toedter.calendar.JDateChooser();
        jLabel1 = new javax.swing.JLabel();
        jdc_fechafinal = new com.toedter.calendar.JDateChooser();
        jcbx_tiendas = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jbtn_generarreporte = new javax.swing.JButton();
        jlbl_cantidadregistros = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jmni_salir = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jmni_actualizar = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sie_invdis.Sie_invdisApp.class).getContext().getResourceMap(com_distri_compras.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel2.border.title"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        jtf_busqueda.setToolTipText(resourceMap.getString("jtf_busqueda.toolTipText")); // NOI18N
        jtf_busqueda.setName("jtf_busqueda"); // NOI18N
        jtf_busqueda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtf_busquedaActionPerformed(evt);
            }
        });

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jbtn_busqueda.setIcon(resourceMap.getIcon("jbtn_busqueda.icon")); // NOI18N
        jbtn_busqueda.setText(resourceMap.getString("jbtn_busqueda.text")); // NOI18N
        jbtn_busqueda.setToolTipText(resourceMap.getString("jbtn_busqueda.toolTipText")); // NOI18N
        jbtn_busqueda.setName("jbtn_busqueda"); // NOI18N
        jbtn_busqueda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_busquedaActionPerformed(evt);
            }
        });

        buttonGroup1.add(jrbtn_folio);
        jrbtn_folio.setText(resourceMap.getString("jrbtn_folio.text")); // NOI18N
        jrbtn_folio.setToolTipText(resourceMap.getString("jrbtn_folio.toolTipText")); // NOI18N
        jrbtn_folio.setActionCommand(resourceMap.getString("jrbtn_folio.actionCommand")); // NOI18N
        jrbtn_folio.setName("jrbtn_folio"); // NOI18N
        jrbtn_folio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbtn_folioActionPerformed(evt);
            }
        });

        buttonGroup1.add(jrbtn_doctoanterio);
        jrbtn_doctoanterio.setText(resourceMap.getString("jrbtn_doctoanterio.text")); // NOI18N
        jrbtn_doctoanterio.setToolTipText(resourceMap.getString("jrbtn_doctoanterio.toolTipText")); // NOI18N
        jrbtn_doctoanterio.setActionCommand(resourceMap.getString("jrbtn_doctoanterio.actionCommand")); // NOI18N
        jrbtn_doctoanterio.setName("jrbtn_doctoanterio"); // NOI18N
        jrbtn_doctoanterio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbtn_doctoanterioActionPerformed(evt);
            }
        });

        buttonGroup1.add(jrbtn_obserdocto);
        jrbtn_obserdocto.setText(resourceMap.getString("jrbtn_obserdocto.text")); // NOI18N
        jrbtn_obserdocto.setToolTipText(resourceMap.getString("jrbtn_obserdocto.toolTipText")); // NOI18N
        jrbtn_obserdocto.setActionCommand(resourceMap.getString("jrbtn_obserdocto.actionCommand")); // NOI18N
        jrbtn_obserdocto.setName("jrbtn_obserdocto"); // NOI18N
        jrbtn_obserdocto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbtn_obserdoctoActionPerformed(evt);
            }
        });

        buttonGroup1.add(jrbtn_cliente);
        jrbtn_cliente.setText(resourceMap.getString("jrbtn_cliente.text")); // NOI18N
        jrbtn_cliente.setToolTipText(resourceMap.getString("jrbtn_cliente.toolTipText")); // NOI18N
        jrbtn_cliente.setActionCommand(resourceMap.getString("jrbtn_cliente.actionCommand")); // NOI18N
        jrbtn_cliente.setName("jrbtn_cliente"); // NOI18N
        jrbtn_cliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbtn_clienteActionPerformed(evt);
            }
        });

        jcbx_filtrarpendientes.setText(resourceMap.getString("jcbx_filtrarpendientes.text")); // NOI18N
        jcbx_filtrarpendientes.setToolTipText(resourceMap.getString("jcbx_filtrarpendientes.toolTipText")); // NOI18N
        jcbx_filtrarpendientes.setName("jcbx_filtrarpendientes"); // NOI18N
        jcbx_filtrarpendientes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbx_filtrarpendientesActionPerformed(evt);
            }
        });

        buttonGroup1.add(jrbtn_idviaje);
        jrbtn_idviaje.setText(resourceMap.getString("jrbtn_idviaje.text")); // NOI18N
        jrbtn_idviaje.setActionCommand(resourceMap.getString("jrbtn_idviaje.actionCommand")); // NOI18N
        jrbtn_idviaje.setName("jrbtn_idviaje"); // NOI18N
        jrbtn_idviaje.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbtn_idviajeActionPerformed(evt);
            }
        });

        jrbtn_pendienterecep.setText(resourceMap.getString("jrbtn_pendienterecep.text")); // NOI18N
        jrbtn_pendienterecep.setActionCommand(resourceMap.getString("jrbtn_pendienterecep.actionCommand")); // NOI18N
        jrbtn_pendienterecep.setName("jrbtn_pendienterecep"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(253, 253, 253)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jtf_busqueda, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jbtn_busqueda))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(161, 161, 161)
                        .addComponent(jrbtn_folio, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jrbtn_doctoanterio)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jrbtn_obserdocto)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jrbtn_cliente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jrbtn_idviaje)
                        .addGap(4, 4, 4)
                        .addComponent(jrbtn_pendienterecep)
                        .addGap(18, 18, 18)
                        .addComponent(jcbx_filtrarpendientes, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtf_busqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jbtn_busqueda))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbx_filtrarpendientes)
                    .addComponent(jrbtn_doctoanterio, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jrbtn_obserdocto, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jrbtn_cliente, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jrbtn_folio, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jrbtn_idviaje)
                    .addComponent(jrbtn_pendienterecep))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel3.setName("jPanel3"); // NOI18N

        jButton1.setIcon(resourceMap.getIcon("jButton1.icon")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jbtn_agregarcompra.setIcon(resourceMap.getIcon("jbtn_agregarcompra.icon")); // NOI18N
        jbtn_agregarcompra.setText(resourceMap.getString("jbtn_agregarcompra.text")); // NOI18N
        jbtn_agregarcompra.setName("jbtn_agregarcompra"); // NOI18N
        jbtn_agregarcompra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_agregarcompraActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbtn_agregarcompra, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 823, Short.MAX_VALUE)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jButton1)
                .addComponent(jbtn_agregarcompra))
        );

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jPanel1.setName("jPanel1"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jtb_comprascatalogo.setModel(this.jtable_modelo);
        jtb_comprascatalogo.setName("jtb_comprascatalogo"); // NOI18N
        jtb_comprascatalogo.setRowHeight(30);
        jtb_comprascatalogo.getTableHeader().setReorderingAllowed(false);
        jtb_comprascatalogo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtb_comprascatalogoMouseClicked(evt);
                if(evt.getClickCount() >= 2)
                {
                    dioclick(evt);
                }
            }
        });
        jScrollPane2.setViewportView(jtb_comprascatalogo);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 1064, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 473, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel1.TabConstraints.tabTitle"), jPanel1); // NOI18N

        jPanel4.setName("jPanel4"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        jtb_comprascatalogo1.setModel(this.jtable_modelofle);
        jtb_comprascatalogo1.setName("jtb_comprascatalogo1"); // NOI18N
        jtb_comprascatalogo1.setRowHeight(30);
        jtb_comprascatalogo1.getTableHeader().setReorderingAllowed(false);
        jScrollPane3.setViewportView(jtb_comprascatalogo1);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 1066, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel4.TabConstraints.tabTitle"), jPanel4); // NOI18N

        jPanel5.setName("jPanel5"); // NOI18N

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        jTable1.setModel(this.jtable_modeloventas);
        jTable1.setName("jTable1"); // NOI18N
        jTable1.setRowHeight(22);
        jTable1.getTableHeader().setReorderingAllowed(false);
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                if(evt.getClickCount() >= 2)
                {
                    dioclick(evt);
                    //System.out.println(" double click" );

                }
            }
        });
        jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTable1KeyPressed(evt);
            }
        });
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTable1KeyPressed(evt);
            }
        });
        jScrollPane4.setViewportView(jTable1);

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jdc_fechainicial.setToolTipText(resourceMap.getString("jdc_fechainicial.toolTipText")); // NOI18N
        jdc_fechainicial.setDateFormatString(resourceMap.getString("jdc_fechainicial.dateFormatString")); // NOI18N
        jdc_fechainicial.setName("jdc_fechainicial"); // NOI18N
        jdc_fechainicial.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jdc_fechainicialKeyPressed(evt);
            }
        });

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jdc_fechafinal.setToolTipText(resourceMap.getString("jdc_fechafinal.toolTipText")); // NOI18N
        jdc_fechafinal.setDateFormatString(resourceMap.getString("jdc_fechafinal.dateFormatString")); // NOI18N
        jdc_fechafinal.setMaxSelectableDate(new java.util.Date(253370790102000L));
        jdc_fechafinal.setName("jdc_fechafinal"); // NOI18N

        jcbx_tiendas.setToolTipText(resourceMap.getString("jcbx_tiendas.toolTipText")); // NOI18N
        jcbx_tiendas.setName("jcbx_tiendas"); // NOI18N
        jcbx_tiendas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbx_tiendasActionPerformed(evt);
            }
        });

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jbtn_generarreporte.setIcon(resourceMap.getIcon("jbtn_generarreporte.icon")); // NOI18N
        jbtn_generarreporte.setText(resourceMap.getString("jbtn_generarreporte.text")); // NOI18N
        jbtn_generarreporte.setToolTipText(resourceMap.getString("jbtn_generarreporte.toolTipText")); // NOI18N
        jbtn_generarreporte.setName("jbtn_generarreporte"); // NOI18N
        jbtn_generarreporte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_generarreporteActionPerformed(evt);
            }
        });

        jlbl_cantidadregistros.setFont(resourceMap.getFont("jlbl_cantidadregistros.font")); // NOI18N
        jlbl_cantidadregistros.setText(resourceMap.getString("jlbl_cantidadregistros.text")); // NOI18N
        jlbl_cantidadregistros.setName("jlbl_cantidadregistros"); // NOI18N

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 1066, Short.MAX_VALUE)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcbx_tiendas, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jdc_fechainicial, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addGap(8, 8, 8)
                .addComponent(jdc_fechafinal, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jbtn_generarreporte, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jlbl_cantidadregistros, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addContainerGap(251, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jcbx_tiendas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jdc_fechainicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jdc_fechafinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1)))
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jbtn_generarreporte, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel5)
                        .addComponent(jlbl_cantidadregistros)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 420, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel5.TabConstraints.tabTitle"), jPanel5); // NOI18N

        jMenuBar1.setName("jMenuBar1"); // NOI18N

        jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N
        jMenu1.setName("jMenu1"); // NOI18N

        jmni_salir.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK));
        jmni_salir.setIcon(resourceMap.getIcon("jmni_salir.icon")); // NOI18N
        jmni_salir.setText(resourceMap.getString("jmni_salir.text")); // NOI18N
        jmni_salir.setName("jmni_salir"); // NOI18N
        jmni_salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmni_salirActionPerformed(evt);
            }
        });
        jMenu1.add(jmni_salir);

        jMenuBar1.add(jMenu1);

        jMenu2.setText(resourceMap.getString("jMenu2.text")); // NOI18N
        jMenu2.setName("jMenu2"); // NOI18N

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0));
        jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem1);

        jmni_actualizar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F5, 0));
        jmni_actualizar.setIcon(resourceMap.getIcon("jmni_actualizar.icon")); // NOI18N
        jmni_actualizar.setText(resourceMap.getString("jmni_actualizar.text")); // NOI18N
        jmni_actualizar.setName("jmni_actualizar"); // NOI18N
        jmni_actualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmni_actualizarActionPerformed(evt);
            }
        });
        jMenu2.add(jmni_actualizar);

        jMenuBar1.add(jMenu2);

        jMenu3.setText(resourceMap.getString("jMenu3.text")); // NOI18N
        jMenu3.setName("jMenu3"); // NOI18N
        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 1071, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(1, 1, 1)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(1, 1, 1)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jtf_busquedaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtf_busquedaActionPerformed
        // TODO add your handling code here:
        this.jbtn_busquedaActionPerformed(evt);
}//GEN-LAST:event_jtf_busquedaActionPerformed

    private void jbtn_busquedaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_busquedaActionPerformed
        // TODO add your handling code here:
        if(JOptionPane.showConfirmDialog(null, "Estan correcto sus Datos?")==0) {
            this.carga_datos(buscamp,this.jtf_busqueda.getText().toUpperCase());
        }
}//GEN-LAST:event_jbtn_busquedaActionPerformed

    private void jrbtn_folioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbtn_folioActionPerformed
        // TODO add your handling code here:
        buscamp=Integer.parseInt(evt.getActionCommand().toString());
}//GEN-LAST:event_jrbtn_folioActionPerformed

    private void jrbtn_doctoanterioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbtn_doctoanterioActionPerformed
        // TODO add your handling code here:
        buscamp=Integer.parseInt(evt.getActionCommand().toString());
}//GEN-LAST:event_jrbtn_doctoanterioActionPerformed

    private void jrbtn_obserdoctoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbtn_obserdoctoActionPerformed
        // TODO add your handling code here:
        buscamp=Integer.parseInt(evt.getActionCommand().toString());
}//GEN-LAST:event_jrbtn_obserdoctoActionPerformed

    private void jrbtn_clienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbtn_clienteActionPerformed
        // TODO add your handling code here:
        buscamp=Integer.parseInt(evt.getActionCommand().toString());
}//GEN-LAST:event_jrbtn_clienteActionPerformed

    private void jcbx_filtrarpendientesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbx_filtrarpendientesActionPerformed
        // TODO add your handling code here:
        if(JOptionPane.showConfirmDialog(null, "Deseas Ver solo Recepciones Pendientes?")==0) {
            this.carga_datos(6,"");
            this.buttonGroup1.setSelected(jrbtn_pendienterecep.getModel(), true);
        }
}//GEN-LAST:event_jcbx_filtrarpendientesActionPerformed

    private void jmni_salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmni_salirActionPerformed
        // TODO add your handling code here:
    if(JOptionPane.showConfirmDialog(null, "Desea Salir?")==0)
            {
                  this.dispose();
            }
    }//GEN-LAST:event_jmni_salirActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        this.jmni_salirActionPerformed(evt);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jmni_actualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmni_actualizarActionPerformed
        // TODO add your handling code here:
          if(JOptionPane.showConfirmDialog(null, "Estan correcto sus Datos?")==0) {
            this.carga_datos(12,"");

        }
    }//GEN-LAST:event_jmni_actualizarActionPerformed

    private void jrbtn_idviajeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbtn_idviajeActionPerformed
        // TODO add your handling code here:
        buscamp=Integer.parseInt(evt.getActionCommand().toString());
    }//GEN-LAST:event_jrbtn_idviajeActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        //x.cierraConexion();   // TODO add your handling code here:
        this.dispose();
}//GEN-LAST:event_jButton1ActionPerformed

    private void jbtn_agregarcompraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_agregarcompraActionPerformed
        // TODO add your handling code here:
        com_distri_compras_alta fcdca=new com_distri_compras_alta();
        fcdca.pack();
        fcdca.setVisible(true);
        
}//GEN-LAST:event_jbtn_agregarcompraActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        // TODO add your handling code here:
}//GEN-LAST:event_jTable1MouseClicked

    private void jTable1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyPressed

        //control enter se utiliza por un rollo de que al dar enter se mostraban dos veces  el documento
        control_enter+=1;
        //System.out.println(evt.getKeyCode());
        if (evt.getKeyCode() == 10) {
            if (control_enter > 1) {
                try {
                    //si entra al if inicializo la variable para evitar qu al regreso entre una vez mas
                    control_enter=0;
                    int fila = jTable1.getSelectedRow();
                    Object valor = jTable1.getValueAt(fila, 0);
                    //JFrame mainFrame = Sie_invdisApp.getApplication().getMainFrame();
                    com_distri_folios_detalle fdd=new com_distri_folios_detalle(String.valueOf(valor));
                    fdd.pack();
                    fdd.setVisible(true);
                } catch (Exception ex) {
                    System.out.println("ERROR no ha elegido en el cuadro de texto");
                }
            }
        }
}//GEN-LAST:event_jTable1KeyPressed

    private void jdc_fechainicialKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jdc_fechainicialKeyPressed
        // TODO add your handling code here:
}//GEN-LAST:event_jdc_fechainicialKeyPressed

    private void jcbx_tiendasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbx_tiendasActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_jcbx_tiendasActionPerformed

    private void jbtn_generarreporteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_generarreporteActionPerformed
        // TODO add your handling code here:
        if(JOptionPane.showConfirmDialog(null, "Estan Correctos sus Datos?")==0)
            {
                String arreglo_tiendas[]=this.jcbx_tiendas.getSelectedItem().toString().split(":");
                SimpleDateFormat formato = new SimpleDateFormat("yyyy-MM-dd");
                String pFechai = formato.format(jdc_fechainicial.getDate());//fecha final de reporte
                String pFecha = formato.format(jdc_fechafinal.getDate());//fecha final de reporte
                this.carga_datos_ventasyprov(2, arreglo_tiendas[2],pFechai, pFecha);
            }
}//GEN-LAST:event_jbtn_generarreporteActionPerformed

    private void dioclick(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
        System.out.println("dio doble  click");
        int fila = jtb_comprascatalogo.getSelectedRow();
        String idfolio = jtb_comprascatalogo.getValueAt(fila, 1).toString();
        String idsta[] = jtb_comprascatalogo.getValueAt(fila, 0).toString().replace("<html>", "").replace("<b><font color=#CC0000>", "").replace("</html>", "").replace("<font></b>", "").split(":");
        if (Integer.valueOf(idsta[0])>4)
            {
               
                 if (com_distri_compras_alta == null)
                        {
                            com_distri_compras_alta = new com_distri_compras_alta(1,idfolio);
                            com_distri_compras_alta.pack();
                            com_distri_compras_alta.setVisible(true);
                        }
                 else
                        {
                        contagarbaje++;
                        System.out.println("dio doble  click y colector:"+contagarbaje);
                            if(contagarbaje>5)
                                {
                                    com_distri_compras_alta=null;
                                    this.getSolicitaGarbageColector();
                                    contagarbaje=0;
                                }
                        com_distri_compras_alta = new com_distri_compras_alta(1,idfolio);
                        com_distri_compras_alta.pack();
                        com_distri_compras_alta.setVisible(true);
                        }

            }
        else
            {
                com_distri_compras_detalle fcdcd=new com_distri_compras_detalle(idfolio);
                fcdcd.pack();
                fcdcd.setVisible(true);
            }
    }

public void getSolicitaGarbageColector()
    {
        try
        {
            System.out.println( "********** INICIO: 'LIMPIEZA GARBAGE COLECTOR' **********" );
            Runtime basurero = Runtime.getRuntime();
            System.out.println( "MEMORIA TOTAL 'JVM': " + basurero.totalMemory() );
            System.out.println( "MEMORIA [FREE] 'JVM' [ANTES]: " + basurero.freeMemory() );
             basurero.gc(); //Solicitando ...
            System.out.println( "MEMORIA [FREE] 'JVM' [DESPUES]: " + basurero.freeMemory() );
            System.out.println( "********** FIN: 'LIMPIEZA GARBAGE COLECTOR' **********" );
        }
catch( Exception e ){
e.printStackTrace();
}
}
 private void jtb_comprascatalogoMouseClicked(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new com_distri_compras().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JButton jbtn_agregarcompra;
    private javax.swing.JButton jbtn_busqueda;
    private javax.swing.JButton jbtn_generarreporte;
    private javax.swing.JCheckBox jcbx_filtrarpendientes;
    private javax.swing.JComboBox jcbx_tiendas;
    private com.toedter.calendar.JDateChooser jdc_fechafinal;
    private com.toedter.calendar.JDateChooser jdc_fechainicial;
    private javax.swing.JLabel jlbl_cantidadregistros;
    private javax.swing.JMenuItem jmni_actualizar;
    private javax.swing.JMenuItem jmni_salir;
    private javax.swing.JRadioButton jrbtn_cliente;
    private javax.swing.JRadioButton jrbtn_doctoanterio;
    private javax.swing.JRadioButton jrbtn_folio;
    private javax.swing.JRadioButton jrbtn_idviaje;
    private javax.swing.JRadioButton jrbtn_obserdocto;
    private javax.swing.JRadioButton jrbtn_pendienterecep;
    private javax.swing.JTable jtb_comprascatalogo;
    private javax.swing.JTable jtb_comprascatalogo1;
    private javax.swing.JTextField jtf_busqueda;
    // End of variables declaration//GEN-END:variables
 private JFrame com_distri_compras_alta;
}
